package com.dragon.repository.domain.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Examine;
import com.dragon.repository.entity.ExamineFile;
import com.dragon.repository.entity.ExamineUser;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ExamineDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private Integer id;

    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "流程类型")
    private Integer streamType;

    @ApiModelProperty(value = "关联主表id")
    private Integer correlationId;

    @ApiModelProperty(value = "0，待审核，1审核通过，2审核不通过")
    private Integer status;

    @ApiModelProperty(value = "审核类型：1、依次顺序审核，2、会签（可同时审核），3、或签")
    private Integer auditType;

    @ApiModelProperty(value = "抄送人名称")
    private String toUsername;

    @ApiModelProperty(value = "申请人id")
    private Integer applicantId;

    @ApiModelProperty(value = "流程总抄送人")
    private String toTotalUsername;

    @ApiModelProperty(value = "所有流程执行完都要抄送的人")
    private Integer toTotalAdmin;

    @ApiModelProperty(value = "抄送是否可编辑，0否，1是")
    private Integer isUpdate;

    @ApiModelProperty(value = "是否有抄送，0否，1是")
    private Integer isSend;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "审批类型 0：表单审核 1：申请修改")
    private Integer examineType;

    @ApiModelProperty(value = "详情")
    private Object detail;

    @ApiModelProperty(value = "是否允许加签:0不允许，1允许")
    private Integer isAddSign;

    @ApiModelProperty(value = "加签类型: 0，未加签，1，前加签，2、后加签")
    private Integer addSignType;

    @ApiModelProperty(value = "加签的审核人id,方便排序操作")
    private Integer signUserId;

    @ApiModelProperty(value = "审核人id")
    private Integer examineAuditUserId;

    @ApiModelProperty(value = "申请人名称")
    private String applicantName;

    @ApiModelProperty(value = "子表数据")
    private List<ExamineUser> examineUsers;

    @ApiModelProperty(value = "审核附件数据")
    private List<ExamineFile> examineFiles;

    @ApiModelProperty(value = "总状态")
    private Integer totalStatus;

    @ApiModelProperty(value = "子表id")
    private Integer examineUserId;

    @ApiModelProperty(value = "子表上次审核状态")
    private Integer examinePreStatus;

    @ApiModelProperty(value = "单条审核状态")
    private Integer examineStatus;

    @ApiModelProperty(value = "子表审核时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date examineAuditTime;



    public ExamineDTO() {}

    public ExamineDTO(Examine entity) {
        if (entity == null){
            entity = new Examine();
        }
        BeanUtils.copyProperties(entity,this);
    }

    public static ExamineDTO convert(Examine entity) {
        return new ExamineDTO(entity);
    }

    public static List<ExamineDTO> convertList(List<Examine> list) {
        List<ExamineDTO> resultList = new ArrayList<>();
        for (Examine entity : list) {
            resultList.add(new ExamineDTO(entity));
        }
        return resultList;
    }}
